package alibaba;

public class Internship {
	public static void main(String[] args) {
		int hello = 123;
		Thread t = new Thread() {
			public void run() {
				for (int i = 1; i <= 5; i++) {
					System.out.print(i + "" + hello + " ");
				}
			}
		};
		t.start();

		// System.out.println(solve(new int[]{2,4,1,3,3,7,1,5,3,6}));
	}

	public static boolean solve(int[] arr) {
		if (arr == null || arr.length < 7)
			return false;

		int m1 = 1, m3 = arr.length - 2;
		int s1 = arr[0], s4 = arr[arr.length - 1];

		while (m3 - m1 > 3) {
			if (s1 == s4)
				break;
			if (s1 < s4)
				s1 += arr[m1++];
			else
				s4 += arr[m3--];
		}
		System.out.println(m1 + " " + m3);
		if (s1 != s4)
			return false;

		int p2 = m1 + 1, p3 = m3 - 1;
		int s2 = arr[p2], s3 = arr[p3];

		while (p3 - p2 > 2) {
			if (s2 < s3)
				s2 += arr[++p2];
			else
				s3 += arr[--p3];
		}
		int m2 = p2 + 1;

		while (!(s1 == s2 && s2 == s3)) {// && s3==s4

			if (m3 - m1 <= 5)
				return false;

			s1 += arr[m1];
			s4 += arr[m3];
			// s2 -= arr[m1]; s3 -= arr[m3];
			m1++;
			m3--;

			do {
				if (m2 < m1)
					s2 -= arr[m1];
				else if (m2 > m1)
					s3 -= arr[m1];

				if (m3 > m2)
					s3 -= arr[m3];
				else if (m3 < m2)
					s2 -= arr[m3];

				if (s1 == s4 || m3 - m1 <= 3)
					break;
				if (s1 < s4) {
					s1 += arr[m1];
					// s2 -= arr[m1];
					m1++;
				} else {
					s4 += arr[m3];
					// s3 -= arr[m3];
					m3--;
				}

			} while (true);

			if (s1 != s4)
				return false;

			if (m1 >= m2) {
				m2 = m1 + 2;
				s2 = arr[m2 - 1];
				s3 = s3 - s2 - arr[m2];
			} else if (m3 <= m2) {
				m2 = m3 - 2;
				s3 = arr[m2 + 1];
				s2 = s2 - s3 - arr[m2];
			}

			int sign = 1;
			if (s2 < s3) {
				while (s2 < s3) {
					s2 += arr[m2++];
					s3 -= arr[m2];
				}
			} else if (s2 > s3) {
				while (s2 > s3) {
					s3 += arr[m2--];
					s2 -= arr[m2];
				}
			}

		}

		return true;
	}
}
